package org.jackysoft.service.impl;

import java.util.Comparator;

import org.jackysoft.entity.nosql.NewsInfo;

public class NewsInfoComparator implements Comparator<NewsInfo> {
    private String order;   
	 

	public NewsInfoComparator(String order) {
		super();
		this.order = order;
	}

	@Override
	public int compare(NewsInfo o1, NewsInfo o2) {
	    if(o1==null || o2 == null)return 0;
	    if(o1.getCreateDate()==null  || o2.getCreateDate() == null)return 0;
	    if(this.order==null)return 0;
	    
		return this.order.equals("desc")?o2.getCreateDate().compareTo(o1.getCreateDate()):o1.getCreateDate().compareTo(o2.getCreateDate());
	}

}
